package com.example.photo.exception;

import com.example.photo.common.BaseResponse;
import com.example.photo.common.ErrorCode;
import com.example.photo.utils.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse<Object> businessException(BusinessException e) {
        log.error("BusinessException: " + e.getErrorCode().getMsg(), e);
        return ResultUtils.fail(e.getErrorCode(), e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<Object> runtimeException(RuntimeException e) {
        log.error("RuntimeException", e);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "运行时异常");
    }
}